home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-04-20 | 1.1 KB | 39 lines |
- import java.io.*;
- import java.net.URL;
-
- public class Wr {
- private static final String FILE = "example";
- public static void main(String[] args) {
- write();
- read();
- }
-
- private static void write() {
- try {
- FileOutputStream f = new FileOutputStream(FILE);
- ObjectOutput s = new ObjectOutputStream(f);
- s.writeObject("My home page is: ");
- s.writeObject(new URL("http://www.learnjava.com"));
- s.close();
- } catch (IOException x) {
- System.out.println(x.getMessage());
- }
- }
-
- private static void read() {
- try {
- FileInputStream f = new FileInputStream(FILE);
- ObjectInput s = new ObjectInputStream(f);
- String text = (String)(s.readObject());
- URL url = (URL)(s.readObject());
- System.out.println(text + url);
- s.close();
- } catch (IOException x) {
- System.out.println(x.getMessage());
- } catch (ClassNotFoundException x) {
- System.out.println(x.getMessage());
- }
- }
-
- }
-